package com.zyk.leetcode;

import java.util.Arrays;

/**
 * @author zhangsan
 * @date 2021/4/27 14:51
 */
public class C66 {


    public static int[] plusOne(int[] digits) {
        for (int i = digits.length - 1; i >= 0; i--) {
            digits[i]++;
            if (digits[i] != 10) {
                return digits;
            }
            digits[i] = 0;
        }
        if (digits[0] == 0) {
            digits = new int[digits.length +1];
            digits[0] = 1;
        }
        return digits;
    }


    // for test
    public static void main(String[] args) {
        int[] digits = {9};
        System.out.println(Arrays.toString(plusOne(digits)));
    }

}
